/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.diagram.component.helper;

import java.util.ArrayList;

import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.uml2.uml.CollaborationUse;
import org.eclipse.uml2.uml.Component;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Interface;
import org.eclipse.uml2.uml.Port;
import org.eclipse.uml2.uml.Property;

import com.cea.papyrus.core.helper.GraphEdgeHelper;
import com.cea.papyrus.core.helper.NodeHelper;
import com.cea.papyrus.diagraminterchange2.di2.Diagram;
import com.cea.papyrus.diagraminterchange2.di2.GraphElement;
import com.cea.papyrus.diagraminterchange2.di2.Uml1SemanticModelBridge;

/**
 * 
 */
public class EdgeRoleBindingHelper extends GraphEdgeHelper {

	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.common.factories.IGraphEdgeFactory#canExecute(com.cea.papyrus.diagraminterchange2.di2.GraphNode, com.cea.papyrus.diagraminterchange2.di2.GraphNode)
	 */	
	/**
	 * 
	 * 
	 * @param target 
	 * @param source 
	 * 
	 * @return 
	 */
	@Override
	public boolean canConnect(Element source,Element target){
		if (source==target){return false;}// generalization not on the same object
		if ((source instanceof CollaborationUse || source instanceof Property)&& target==null){// they are  classifiers
			return true;
		}
		if (source instanceof CollaborationUse && target instanceof Property){// they are  classifiers
			return true;
		}
		if (source instanceof Property && target instanceof CollaborationUse){// they are  classifiers
			return true;
		}
		if (source instanceof Port && target instanceof Port){// they are  classifiers
			return true;
		}
		if (source instanceof Port && target instanceof Interface){// they are  classifiers
			return true;
		}
		if (source instanceof Component && target instanceof Interface){// they are  classifiers
			return true;
		}
		if (source instanceof Interface && target instanceof Interface){// they are  classifiers
			return true;
		}
		return false;

	}
	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.common.factories.GraphEdgeFactory#canExecute(com.cea.papyrus.diagraminterchange2.di2.GraphNode)
	 */
	/**
	 * 
	 * 
	 * @param source 
	 * 
	 * @return 
	 */
	@Override
	public boolean canCreateGraphElement(GraphElement source){
		Element eltSource=null;
		if (source.getSemanticModel()!=null ){
			if (((Uml1SemanticModelBridge)source.getSemanticModel()).getElement()!=null){
				eltSource=((Uml1SemanticModelBridge)source.getSemanticModel()).getElement();
				if (eltSource instanceof  Property|| eltSource instanceof CollaborationUse){// they are  comment
					return true;
				}
				if (eltSource instanceof Port || eltSource instanceof Component || eltSource instanceof Interface ){// they are  classifiers
					return true;
				}
			}
		}
		return false;
	}
	
	/**
	 * 
	 * 
	 * @param umlChild 
	 * @param size 
	 * @param location 
	 * @param parent 
	 * 
	 * @return 
	 */
	public GraphElement createGraphElement(Element umlChild, GraphElement parent, Point location, Dimension size){
		GraphElement ge=super.createGraphElement(umlChild, parent, location, size);
		NodeHelper nh= new NodeHelper();
		nh.createGraphElement(null, ge, new Point(0,10), null);
		return ge;
	}
	/*
	 * (non-Javadoc)
	 * @see com.cea.papyrus.common.factories.GraphEdgeFactory#createGraphEdge(org.eclipse.uml2.uml.Element, com.cea.papyrus.diagraminterchange2.di2.Diagram)
	 */
	/**
	 * 
	 * 
	 * @param umlElement 
	 * @param diagram 
	 * 
	 * @return 
	 */
	@Override
	public ArrayList createGraphEdge(Element umlElement, Diagram diagram){

		return new ArrayList();
	}

	/**
	 * 
	 * 
	 * @param umlParent 
	 * @param name 
	 * 
	 * @return 
	 */
	public  org.eclipse.uml2.uml.Element createUMLElement(String name, org.eclipse.uml2.uml.Element umlParent){
		return null;		
	}


	/**
	 * 
	 * 
	 * @param umlParent 
	 * 
	 * @return 
	 */
	public boolean canCreateUMLElement(Element umlParent) {
		return false;
	}


	/**
	 * 
	 * 
	 * @param element 
	 * @param umlParent 
	 * 
	 * @return 
	 */
	public boolean addUMLElement(Element element, Element umlParent) {
		return false;
	}


	/**
	 * 
	 * 
	 * @param element 
	 * @param umlParent 
	 * 
	 * @return 
	 */
	public boolean removeUMLElement(Element element, Element umlParent) {

		return false;
	}
	
	/**
	 * 
	 * 
	 * @param target 
	 * @param link 
	 * @param source 
	 * 
	 * @return 
	 */
	public boolean connect(Element source, Element target, Element link) {
			return true;
	}
	
	/**
	 * 
	 * 
	 * @param target 
	 * @param link 
	 * @param source 
	 * 
	 * @return 
	 */
	public boolean deconnect(Element source, Element target, Element link) {
		return true;
	}

	/**
	 * 
	 * 
	 * @return 
	 */
	public String getBaseString() {
		return "RoleBinding"; //$NON-NLS-1$
	}

}
